#pragma once
#include "xKernel/IxAttributeManager.h"
#include "xKernel/IxElement.h"
#include "xKernel/IxEventObserver.h"

class CxElement
    : public IxElement
{
    typedef std::list< CAdapt< CComPtr<IxEventObserver> > >   OBSERVERLIST;
public:
    CxElement();
    virtual ~CxElement();

    // interface of IxElement
    HRESULT GetID(LPINT pnID);
    HRESULT SetID(INT nID);

    // interface of IxEventSupporter
    HRESULT AddObserver(IxEventObserver* pObserver);
    HRESULT RemoveObserver(IxEventObserver* pObserver);
    HRESULT ClearObserver();
    HRESULT RaiseEvent(INT nEventId, VOID* pData);

protected:

    template<class T>
    CComPtr<T> GetEntity()
    {
        CComPtr<T> p;
        QueryInterface(__uuidof(T), (VOID**)&p);
        return p;
    }

protected:
    INT                 m_nID;
    OBSERVERLIST        m_ltObservers;
};